package com.jd.platform.gobrs.client.enable;

import com.jd.platform.gobrs.client.config.BootstrapProperties;
import com.jd.platform.gobrs.common.exception.ConfigEmptyException;
import io.netty.util.internal.StringUtil;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.StringUtils;

/**
 * Before check configuration.
 * @author sizegang
 */
public class BeforeCheckConfiguration {
    @Bean
    public BeforeCheck BeforeCheckConfiguration(@Autowired(required = true) BootstrapProperties properties,
                                            ConfigurableEnvironment environment) {
        if (properties != null && properties.getEnable()) {
            String etcdServer = properties.getEtcdServer();
            if (StringUtils.isEmpty(etcdServer)) {
                throw new ConfigEmptyException(
                        "Web server failed to start. The gobrs starting etcdServer is empty please check"
                );
            }
            String appName = properties.getAppName();
            if (StringUtils.isEmpty(appName)) {
                throw new ConfigEmptyException(
                        "Web server failed to start. The dynamic thread pool appName is empty please check"
                );
            }
        }

        return new BeforeCheck();
    }

    public class BeforeCheck {

    }

}
